import request from '@/common/js/request.js'

const ACCESS_TOKEN_KEY = "Cache-Id"

const authorizeUrl =
	"https://open.weixin.qq.com/connect/oauth2/authorize?appid={appid}&redirect_uri={redirect_uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect"

const dev = {
	// app接口
	API_URL_APP: "http://192.168.31.188:6601/app",
	// 文件上传地址
	API_URL_UPLOAD: "http://192.168.31.188:6601/file/v1/local/upload",
	//文件系统访问地址
	API_URL_STATIC: "http://192.168.31.188:6601/file/assets/",
	// 欢迎页-授权中转
	PAGE_WELCOME: "http://xxl.nicegean.com/m/pages/welcome?redirect_uri={redirect_uri}",
	// 统一认证登录页
	PAGE_LOGIN: "http://xxl.nicegean.com/m/pages/login/login?service={redirect_uri}",
	// 微信appid
	appid: "wx322f914b006ccde3"
}
const prod = {
	// app接口
	API_URL_APP: "https://lab.v.zzu.edu.cn/api/app",
	// 文件上传地址
	API_URL_UPLOAD: "https://lab.v.zzu.edu.cn/api/file/v1/local/upload",
	//文件系统访问地址
	API_URL_STATIC: "https://lab.v.zzu.edu.cn/api/file/assets/",
	// 欢迎页-授权中转
	PAGE_WELCOME: "https://lab.v.zzu.edu.cn/m/pages/welcome?redirect_uri={redirect_uri}",
	// 统一认证登录页
	PAGE_LOGIN: "https://cas.s.zzu.edu.cn/cas/login?loginType=1&service={redirect_uri}",
	// 微信appid
	appid: "wx465da5ddec350e07"
}

/**
 * 环境变量
 */
export function getEnv() {
	return {
		ACCESS_TOKEN_KEY,
		authorizeUrl,
		...(process.env.NODE_ENV === 'development' ? dev : prod)
	}
}

/**
 * get请求
 * @param url
 * @param data
 */
export function get(url, data) {
	return request.get({
		url,
		data,
	})
}

/**
 * post请求
 * @param url
 * @param data
 */
export function post(url, data) {
	return request.post({
		url,
		data,
	})
}


/**
 * 通用文件上传
 * @param url
 * @param data
 */
export function uniUpload(tempFilePath, data) {
	return request.upload({
		url: getEnv().API_URL_UPLOAD,
		tempFilePath,
		data
	})
}

/**
 * base64文件上传
 * @param url
 * @param data
 */
export function base64Upload(base64, name, data) {
	return request.post({
		url: getEnv().API_URL_UPLOAD + '/base64',
		data: {
			base64: base64,
			name: name,
			...data
		},
	})
}